//
//  CrazyChatMineOrderCell.m
//  webSocket
//
//  Created by 马军凯 on 2019/2/15.
//  Copyright © 2019年 ZH. All rights reserved.
//

#import "CrazyChatMineOrderCell.h"

@interface CrazyChatMineOrderCell ()

@property (nonatomic, strong) UIImageView *mineHeadImageView; //头像
@property (nonatomic, strong) UIView *mineOrderBackView; //背景
@property (nonatomic, strong) UIImageView *mineOrderBackImageView; //背景图片
@property (nonatomic, strong) UIImageView *mineOrderImageView; //订单图片
@property (nonatomic, strong) UILabel *mineOrderTitleLabel; //订单标题
@property (nonatomic, strong) UILabel *mineOrderAttrLabel; //订单属性
@property (nonatomic, strong) UILabel *mineOrderPriceLabel; //订单价格
@property (nonatomic, strong) UILabel *mineOrderNumLabel; //订单数量
@property (nonatomic, strong) UILabel *mineOrderStatusLabel; //订单状态

@end

@implementation CrazyChatMineOrderCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}


+ (instancetype)cellWithTableView:(UITableView *)tableView {
    static NSString *identifier = CrazyChatMineOrderIdentifier;
    
    //缓存中取
    CrazyChatMineOrderCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    
    //创建
    if (!cell) {
        cell = [[CrazyChatMineOrderCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    
    
    return cell;
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor clearColor];
        //头像
        self.mineHeadImageView = [[UIImageView alloc] init];
        self.mineHeadImageView.frame = CGRectMake(CRAZY_SCREEN_WIDTH - 55, 10, 40, 40);
        [self.contentView addSubview:self.mineHeadImageView];
        //背景
        self.mineOrderBackView = [[UIView alloc] init];
        self.mineOrderBackView.frame = CGRectMake(60, 10, CRAZY_SCREEN_WIDTH - 120, 100);
        [self.contentView addSubview:self.mineOrderBackView];
        //背景图片
        self.mineOrderBackImageView = [[UIImageView alloc] init];
        self.mineOrderBackImageView.frame = self.mineOrderBackView.bounds;
        self.mineOrderBackImageView.image = [[UIImage imageNamed:@"Crazy_chat_rightPic@2x.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(23, 15, 7, 15) resizingMode:UIImageResizingModeStretch];
        [self.mineOrderBackView addSubview:self.mineOrderBackImageView];
        //图片
        self.mineOrderImageView = [[UIImageView alloc] init];
        self.mineOrderImageView.frame = CGRectMake(8, 10, 80, 80);
        [self.mineOrderBackView addSubview:self.mineOrderImageView];
        //标题
        self.mineOrderTitleLabel = [[UILabel alloc] init];
        self.mineOrderTitleLabel.numberOfLines = 2;
        self.mineOrderTitleLabel.font = [UIFont systemFontOfSize:14];
        self.mineOrderTitleLabel.textColor = CRAZY_RGBR(33);
        [self.mineOrderBackView addSubview:self.mineOrderTitleLabel];
        //价格
        self.mineOrderPriceLabel = [[UILabel alloc] init];
        self.mineOrderPriceLabel.textColor = [UIColor redColor];
        self.mineOrderPriceLabel.font = [UIFont systemFontOfSize:14];
        [self.mineOrderBackView addSubview:self.mineOrderPriceLabel];
        //属性
        self.mineOrderAttrLabel = [[UILabel alloc] init];
        self.mineOrderAttrLabel.textColor = CRAZY_RGBR(99);
        self.mineOrderAttrLabel.font = [UIFont systemFontOfSize:12];
        [self.mineOrderBackView addSubview:self.mineOrderAttrLabel];
        //数量
        self.mineOrderNumLabel = [[UILabel alloc] init];
        self.mineOrderNumLabel.textColor = CRAZY_RGBR(99);
        self.mineOrderNumLabel.font = [UIFont systemFontOfSize:12];
        [self.mineOrderBackView addSubview:self.mineOrderNumLabel];
        //查看
        self.mineOrderCheckBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        self.mineOrderCheckBtn.frame = self.mineOrderBackView.bounds;
        [self.mineOrderBackView addSubview:self.mineOrderCheckBtn];
        //重发按钮
        self.mineOrderRepeatBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.mineOrderRepeatBtn setImage:[UIImage imageNamed:@"Crazy_chat_repeat.png"] forState:UIControlStateNormal];
        self.mineOrderRepeatBtn.size = CGSizeMake(30, 30);
        self.mineOrderRepeatBtn.x = 20;
        self.mineOrderRepeatBtn.y = 10 + self.mineOrderBackView.height / 2 - 15;
        [self.contentView addSubview:self.mineOrderRepeatBtn];
        //状态
        self.mineOrderStatusLabel = [[UILabel alloc] init];
        self.mineOrderStatusLabel.frame = CGRectMake(self.mineOrderBackView.width - 40 - 12, self.mineOrderBackView.height - 10 - 15, 40, 15);
        [self.mineOrderStatusLabel corner_radius:15 / 2];
        self.mineOrderStatusLabel.backgroundColor = CRAZY_RGB(254, 239, 239);
        self.mineOrderStatusLabel.textColor = CRAZY_RGB(244, 126, 127);
        self.mineOrderStatusLabel.textAlignment = NSTextAlignmentCenter;
        self.mineOrderStatusLabel.font = [UIFont systemFontOfSize:9];
        [self.mineOrderBackView addSubview:self.mineOrderStatusLabel];
    }
    return self;
}

//赋值
- (void)setCellValueWithHeadURL:(NSString *)headURL picURL:(NSString *)picURL title:(NSString *)title attr:(NSString *)attr price:(NSString *)price count:(NSString *)count status:(NSString *)status repeatType:(NSString *)repeatType {
    //头像
    [self.mineHeadImageView sd_setImageWithURL:[NSURL URLWithString:headURL] placeholderImage:CRAZY_DEFAULT_HEADIMAGE];
    //图片
    [self.mineOrderImageView sd_setImageWithURL:[NSURL URLWithString:picURL] placeholderImage:CRAZY_DEFAULT_LOADIMAGE];
    //标题
    self.mineOrderTitleLabel.text = title;
    CGSize maxSize = CGSizeMake(self.mineOrderBackView.width - 105, 40);
    CGSize size = [self.mineOrderTitleLabel sizeThatFits:maxSize];
    self.mineOrderTitleLabel.frame = CGRectMake(93, 10, self.mineOrderBackView.width - 105, size.height);
    //属性
    self.mineOrderAttrLabel.text = ([attr isEqualToString:@""]) ? @"无属性" : attr;
    //价格
    self.mineOrderPriceLabel.text = [NSString stringWithFormat:@"%@%@", @"¥", price];
    //数量
    self.mineOrderNumLabel.text = [NSString stringWithFormat:@"%@%@", @"x", count];
    //状态
    switch ([status integerValue]) {
        case 0: {
            self.mineOrderStatusLabel.text = @"待付款";
        }
            break;
        case 1: {
            self.mineOrderStatusLabel.text = @"待配送";
        }
            break;
        case 2: {
            self.mineOrderStatusLabel.text = @"配送中";
        }
            break;
        case 3: {
            self.mineOrderStatusLabel.text = @"已完成";
        }
            break;
        case 4: {
            self.mineOrderStatusLabel.text = @"已关闭";
        }
            break;
        case 5: {
            self.mineOrderStatusLabel.text = @"退款中";
        }
            break;
        case 6: {
            self.mineOrderStatusLabel.text = @"已取消";
        }
            break;
        default:
            break;
    }
    //价格
    [self.mineOrderPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(93);
        make.bottom.mas_equalTo(-10);
    }];
    //属性
    [self.mineOrderAttrLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(93);
        make.bottom.mas_equalTo(self.mineOrderPriceLabel.mas_top).offset(-8);
        make.width.mas_equalTo(self.mineOrderBackView.width - 105);
    }];
    //数量
    [self.mineOrderNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.mineOrderAttrLabel);
        make.bottom.mas_equalTo(self.mineOrderPriceLabel.mas_bottom);
    }];
    //重发按钮
    if ([repeatType isEqualToString:@"1"]) {
        self.mineOrderRepeatBtn.hidden = NO;
    } else {
        self.mineOrderRepeatBtn.hidden = YES;
    }
}




- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
